package com.whatech.mall.order.feignclient;

import com.whatech.mall.order.model.dto.productservice.ProductDTO;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * ProductServiceFeignClient 的降级处理工厂类。
 */
@Slf4j
@Component
public class ProductServiceFeignClientFallbackFactory implements FallbackFactory<ProductServiceFeignClient> {

    @Override
    public ProductServiceFeignClient create(Throwable t) {
        return new ProductServiceFeignClient() {
            @Override
            public ProductDTO findProductById(Long id) {
                log.warn("ProductServiceFeignClient.findProductById() is block or fallback", t);
                return ProductDTO.builder().id(id).build();
            }
        };
    }

}
